import { authService } from '../lib/authService';

// Demo专用客户列表
export const DEMO_ONLY_CUSTOMERS = ["吴磊", "陈浩", "赵杰", "杨丽", "赵静", "刘磊", "刘军", "吴丽", "王敏", "黄芳"];

// 客户过滤函数
export function filterCustomersByRole<T extends { name: string }>(
  allCustomers: T[],
  managerName?: string
): T[] {
  // 如果没有提供管理员名称，从authService获取
  const manager = managerName ? { name: managerName } : authService.getManager();
  
  // 如果没有管理员信息，过滤掉demo专用客户
  if (!manager) {
    return allCustomers.filter(customer => 
      customer.name && !DEMO_ONLY_CUSTOMERS.includes(customer.name)
    );
  }

  const userName = manager.name.toLowerCase();

  // 如果用户名以 "guangda" 开头，只显示demo专用客户
  if (userName.startsWith('guangda') || userName.startsWith('demo')) {
    return allCustomers.filter(customer => 
      customer.name && DEMO_ONLY_CUSTOMERS.includes(customer.name)
    );
  }
  // 其他用户，过滤掉demo专用客户
  return allCustomers.filter(customer => 
    customer.name && !DEMO_ONLY_CUSTOMERS.includes(customer.name)
  );
}

// 判断是否为demo用户的工具函数
export function isDemoUser(managerName?: string): boolean {
  const manager = managerName ? { name: managerName } : authService.getManager();
  return manager ? manager.name.toLowerCase().startsWith('demo') : false;
}

// 判断是否为广发用户的工具函数
export function isGuangdaUser(managerName?: string): boolean {
  const manager = managerName ? { name: managerName } : authService.getManager();
  return manager ? manager.name.toLowerCase().startsWith('guangda') : false;
} 